namespace Warehouse

open System.Windows.Data
open Warehouse.Controls

open Wpf.Mvc

type ProductSearchEvents = 
    | Search

type ProductSearchPartialView(control) = 
    inherit PartialView<ProductSearchEvents, ProductSearchModel, ProductSearchControl>(control)

    override this.EventStreams = 
        [
            this.Control.Search.ClickToValue Search
        ]

    override this.SetBindings model = 
        Binding.FromExpression 
            <@ 
                this.Control.Products.ItemsSource <- model.Products
                this.Control.Products.SelectedItem <- model.SelectedProduct
                this.Control.ItemsCount.Text <- string model.Products.Count
                this.Control.Search.IsEnabled <- not model.IsSearchInProgress
            @>

        Binding.UpdateSourceOnChange 
            <@ 
                model.Filter <- this.Control.Filter.Text 
            @>
